import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
import App from './App'
/*引入axios*/
import axios from 'axios'
//设置请求的公共前缀
axios.defaults.baseURL="http://localhost:8081/api";
//请求的公共前缀
/*给vue类型添加$http原型，方便在组件中获取axios对象*/
Vue.prototype.$http = axios;

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
//import './assets/theme/theme-green/index.css'

//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
//准备的路由，路径映射组件代码放到此文件中
import routes from './routes'

import 'font-awesome/css/font-awesome.min.css'

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

//NProgress.configure({ showSpinner: false });

//创建路由
const router = new VueRouter({
  routes
})

//前端的拦截器
/*
router.beforeEach((to, from, next) => {
  //NProgress.start();
    //如果我访问的目标路径是/login，我就删除前端的session中的user
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  //user为空并且访问的目标路径不是/login,我就跳转到/login资源
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    //放行，让其执行目标路径
    next()
  }
})
*/

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

